package casino;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class MenuButton extends MenuItem{
	private static final long serialVersionUID = 1L;
	protected BufferedImage normal = getImage(new File("images/button.png"));
	protected BufferedImage pressed = getImage(new File("images/button_pressed.png"));
	protected Menu link;
	protected boolean hovering;
	protected TextLayout textLayout;
	
	public MenuButton(){}
	
	public MenuButton(Menu m, int x, int y, int w, int h, String content, int fontSize, Menu link){
		super(m, x, y, w, h, content, fontSize);
		this.link = link;
	}
	
	public MenuButton(Menu m, int x, int y, int w, int h, String content, int fontSize, Menu link, String f){
		super(m, x, y, w, h, content, fontSize, f);
		this.link = link;
	}
	
	protected void draw(Graphics2D g){
		g.setColor(Color.black);
		textLayout = new TextLayout(info, font, g.getFontRenderContext());
		if(hovering){
			g.drawImage(pressed, x, y, width, height, host.casino);
			g.drawRect(x, y, width, height);
		}else{
			g.drawImage(normal, x, y, width, height, host.casino);
			g.drawRect(x, y, width, height);
		}
		g.setFont(font);
		textLayout.draw(g, x+(int)(this.width-textLayout.getBounds().getWidth())/2, y+(int)(this.height+textLayout.getBounds().getHeight())/2);
	}
	
	public void onHover(int x, int y){
		hovering = true;
	}
	
	public void offHover(int x, int y){
		hovering = false;
	}
	
	public void clicked(MouseEvent e){
		if(link != null){
			host.subMenu = link;
		}
	}
	
	public BufferedImage getImage(File f){
		try{
			return ImageIO.read(f);
		}catch (IOException e){
			return null;
		}
	}
	
	public void keyPress(int keycode){}
}
